<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }

    public function main()
    {
        $data = [];
        $jiaoyu = Db::table('fa_shopro_goods')
                ->field('id,title,subtitle,image,price,original_price')
                ->where('status','up')
                ->where('category_ids',12)
                ->order('weigh','desc')
                ->limit(4)->select();
        $data['jiaoyu'] = ['list'=>$jiaoyu,'name'=>'教育专区'];
        $shangwu = Db::table('fa_shopro_goods')
                    ->field('id,title,subtitle,image,price,original_price')
                    ->where('status','up')
                    ->where('category_ids','in',Db::table('fa_shopro_category')->where('pid',8)->column('id'))
                    ->order('weigh','desc')
                    ->limit(1)->select();
        $data['shangwu'] = ['list'=>$shangwu,'name'=>'商务服务'];
        
        $chanpin = Db::table('fa_shopro_goods')
                    ->field('id,title,subtitle,image,price,original_price')
                    ->where('status','up')
                    ->where('category_ids','in',Db::table('fa_shopro_category')->where('pid',9)->column('id'))
                    ->order('weigh','desc')
                    ->limit(3)->select();
        $data['chanpin'] = ['list'=>$chanpin,'name'=>'产品专区'];

        $xiangmu = Db::table('fa_shopro_goods')
                    ->field('id,title,subtitle,image,price,original_price')
                    ->where('status','up')
                    ->where('category_ids','in',Db::table('fa_shopro_category')->where('pid',10)->column('id'))
                    ->order('weigh','desc')
                    ->limit(2)->select();
        $data['xiangmu'] = ['list'=>$xiangmu,'name'=>'项目专区'];

        $rongzi = Db::table('fa_shopro_goods')
                    ->field('id,title,subtitle,image,price,original_price')
                    ->where('status','up')
                    ->where('category_ids',32)
                    ->order('weigh','desc')
                    ->limit(3)->select();
        $data['rongzi'] = ['list'=>$rongzi,'name'=>'融资专区'];
        
        $this->success($data);
    }

}
